package com.Web.servlet;

import com.alibaba.fastjson2.JSON;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/selectstudent")
public class ServlectStudent extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置内容类型
        resp.setContentType("application/json;charset=utf-8");
        //查询学生信息
        List<Student> students = JDBCUtils.query(Student.class, "select * from student");
        //转换数据为JSON格式
        String str = JSON.toJSONString(students);
        //响应流发送数据给用户
        resp.getWriter().write(str);
    }
}
